#!/usr/bin/env bash
set -e
echo "start to prepare env"
cur_path=$(pwd)

chmod +x /root/repo/ci-repos/.common_scripts/common.sh
source /root/repo/ci-repos/.common_scripts/common.sh
prepare_git $1 $2
prepare_conan2 $3 $4
prepare_bingo

cd $cur_path

echo "====== Check version consistency ======"
if [ "$VERSION_CHECK" = 'true' ]; then
    cmd=(python3 /root/repo/ci-repos/manifest/scripts/version_consistency_check.py)

    if [ -n "$SUBSYS_PATH" ]; then
        cmd+=("-s" "$SUBSYS_PATH")
    fi

    if [ -n "$FOLDERS" ]; then
        IFS=';' read -r -a folders_array <<< "$FOLDERS"
        cmd+=("-f")
        for folder in "${folders_array[@]}"; do
            cmd+=("$folder")
        done
    fi

    "${cmd[@]}"
fi

echo "======Start personal build====="
bingo build -b openUBMC -bt debug